<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="策略名称" prop="tacticsname">
        <el-input
          v-model="queryParams.tacticsname"
          placeholder="请输入策略名称"
          clearable
          @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="组织编码" prop="saleorgnumber">
        <el-input
          v-model="queryParams.saleorgnumber"
          placeholder="请输入组织编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="组织名称" prop="saleorgname">
        <el-input
          v-model="queryParams.saleorgname"
          placeholder="请输入组织名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="生效日期" prop="startdate">
        <el-date-picker clearable
          v-model="queryParams.startdate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择生效日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="失效日期" prop="enddate">
        <el-date-picker clearable
          v-model="queryParams.enddate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择失效日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择状态" clearable>
          <el-option
            v-for="dict in dict.type.yes_no_audit"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="分录组织编码" prop="params.orgnumber">
        <el-input
          v-model="queryParams.params.orgnumber"
          placeholder="请输入组织名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="分录组织名称" prop="params.orgname">
        <el-input
          v-model="queryParams.params.orgname"
          placeholder="请输入组织名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="价格类型" prop="params.pricetype">
        <el-select v-model="queryParams.params.pricetype" placeholder="请选择价格类型" clearable>
          <el-option
            v-for="dict in dict.type.settlement_price_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="品类编码" prop="params.categorynumber">
        <el-input
          v-model="queryParams.params.categorynumber"
          placeholder="请输入品类编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="品类名称" prop="params.categoryname">
        <el-input
          v-model="queryParams.params.categoryname"
          placeholder="请输入品类名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物料编码" prop="params.materialnumber">
        <el-input
          v-model="queryParams.params.materialnumber"
          placeholder="请输入物料编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物料名称" prop="params.materialname">
        <el-input
          v-model="queryParams.params.materialname"
          placeholder="请输入物料名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="客户分组" prop="params.groupnumber">
        <el-input
          v-model="queryParams.params.groupnumber"
          placeholder="请输入客户分组"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['settlementCenter/basedata:settlementrate:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['settlementCenter/basedata:settlementrate:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['settlementCenter/basedata:settlementrate:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['settlementCenter/basedata:settlementrate:export']"
        >导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-sort"
          size="mini"
          @click="closeOrOpenAll"
        >展开/折叠</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading"
              :data="settlementrateList"
              ref="serveTable"
              row-key="id"
              :expand-row-keys="settlementRateExpandRowKeys"
              @row-click="rowClick"
              :default-expand-all="false"
              :row-class-name="rowBillHeadIndex"
              @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" prop="index" width="50px"/>
      <el-table-column type="expand">
        <template slot-scope="props">
          <!--          <div class="conWrap" style="text-align: left;line-height: 16px;font-size: 14px;position: relative;top: -10px;">-->
          <!--            <span>价格策略名称：{{props.row.pricetactics}}</span>-->
          <!--            <span style="margin-left:42px;">生效日期：{{props.row.startdate}}</span>-->
          <!--            <span style="margin-left:42px;">失效日期：{{props.row.enddate}}</span>-->
          <!--          </div>-->
          <el-table v-bind:data="props.row.omsSettlementrateentrytwoList" :row-class-name="rowBillHeadIndex" :default-expand-all="true" :show-header="true" max-height="600px" class="childTable1">
            <el-table-column label="序号" align="center" prop="index" width="50"/>
            <el-table-column align="center"
                             label="组织编码"
                             width="550">
              <template slot-scope="scope">
                <div class="name-b">{{scope.row.orgnumber}}</div>
              </template>
            </el-table-column>
            <el-table-column prop="materialname" align="center"
                             label="组织名称"
                             width="550">
              <template slot-scope="scope">
                <div class="name-b">{{scope.row.orgname}}</div>
              </template>
            </el-table-column>
          </el-table>
          <el-table v-bind:data="props.row.omsSettlementrateentryList" :row-class-name="rowBillHeadIndex" :default-expand-all="true" :show-header="true" max-height="600px" class="childTable">
            <el-table-column label="序号" align="center" prop="index" width="50"/>
            <el-table-column prop="pricetype" align="center"
                             label="价格类型"
                             width="180">
              <template slot-scope="scope">
                <dict-tag :options="dict.type.settlement_price_type" :value="scope.row.pricetype"/>
<!--                <div class="name-b">{{scope.row.pricetype}}</div>-->
              </template>
            </el-table-column>
<!--            <el-table-column label="状态" align="center" prop="status">-->
<!--              <template slot-scope="scope">-->
<!--                <dict-tag :options="dict.type.settlement_price_type" :value="scope.row.status"/>-->
<!--              </template>-->
<!--            </el-table-column>-->
            <el-table-column align="center"
                             label="品类编码"
                             width="180">
              <template slot-scope="scope">
                <div class="name-b">{{scope.row.categorynumber}}</div>
              </template>
            </el-table-column>
            <el-table-column prop="categoryname" align="center"
                             label="品类名称"
                             width="180">
              <template slot-scope="scope">
                <div class="name-b">{{scope.row.categoryname}}</div>
              </template>
            </el-table-column>
            <el-table-column prop="materialnumber" align="center"
                             label="物料编码"
                             width="180">
              <template slot-scope="scope">
                <div class="name-b">{{scope.row.materialnumber}}</div>
              </template>
            </el-table-column>
            <el-table-column prop="materialname" align="center"
                             label="物料名称"
                             width="180">
              <template slot-scope="scope">
                <div class="name-b">{{scope.row.materialname}}</div>
              </template>
            </el-table-column>
            <el-table-column prop="unitname" align="center"
                             label="单位"
                             width="180">
              <template slot-scope="scope">
                <div class="name-b">{{scope.row.unitname}}</div>
              </template>
            </el-table-column>

            <el-table-column prop="groupnumber" align="center"
                             label="客户分组"
                             width="180">
              <template slot-scope="scope">
                <div class="name-b">{{scope.row.groupnumber}}</div>
              </template>
            </el-table-column>
            <el-table-column prop="scale" align="center"
                             label="比例"
                             width="180">
              <template slot-scope="scope">
                <div class="name-b">{{scope.row.scale}}</div>
              </template>
            </el-table-column>
            <el-table-column prop="taxprice" align="center"
                             label="含税单价"
                             width="180">
              <template slot-scope="scope">
                <div class="name-b">{{scope.row.taxprice}}</div>
              </template>
            </el-table-column>
            <el-table-column prop="priority" align="center"
                             label="优先级"
                             width="180">
              <template slot-scope="scope">
                <div class="name-b">{{scope.row.priority}}</div>
              </template>
            </el-table-column>
          </el-table>
        </template>
      </el-table-column>
<!--      <el-table-column label="ID" align="center" prop="id" />-->
      <el-table-column label="策略名称" align="center" prop="tacticsname" />
      <el-table-column label="组织编码" align="center" prop="saleorgnumber" />
      <el-table-column label="组织名称" align="center" prop="saleorgname" />
      <el-table-column label="生效日期" align="center" prop="startdate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.startdate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="失效日期" align="center" prop="enddate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.enddate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.yes_no_audit" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click.native.stop="handleUpdate(scope.row)"
            v-hasPermi="['settlementCenter/basedata:settlementrate:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click.native.stop="handleDelete(scope.row)"
            v-hasPermi="['settlementCenter/basedata:settlementrate:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改价格策略对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="策略名称" prop="tacticsname">
              <el-input v-model="form.tacticsname" placeholder="请输入策略名称"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="状态" prop="status">
              <el-select v-model="form.status" placeholder="请选择状态" style="width: 380px">
                <el-option
                  style="width: 380px"
                  v-for="dict in dict.type.yes_no_audit"
                  :key="dict.value"
                  :label="dict.label"
                  :value="Number(dict.value)"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="组织编码" prop="saleorgnumber">
                  <el-input
                    @change="orgChange"
                    v-model="form.saleorgnumber"
                    placeholder="请输入组织编码"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="组织名称" prop="saleorgname">
              <el-input v-model="form.saleorgname" placeholder="请输入组织名称" readonly/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="生效日期" prop="startdate">
              <el-date-picker clearable
                              style="width: 380px"
                              v-model="form.startdate"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="请选择生效日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="失效日期" prop="enddate">
              <el-date-picker clearable
                              style="width: 380px"
                              v-model="form.enddate"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="请选择失效日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>




        <el-divider content-position="center">价格策略组织分录信息</el-divider>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAddOmssettlementrateentryTwo">添加</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="danger" icon="el-icon-delete" size="mini" @click="handleDeleteOmssettlementrateentryTwo">删除</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="danger" icon="el-icon-plus" size="mini" @click="importTemplateEntry2">下载导入模板</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="danger" icon="el-icon-plus" size="mini" @click="importExcelsettlementrateentry2">导入数据</el-button>
          </el-col>
        </el-row>
        <el-table :data="omsSettlementrateentrytwoList"
                  :row-class-name="rowOmssettlementrateentryTwoIndex"
                  @selection-change="handleOmssettlementrateentryTwoSelectionChange"
                  ref="OmssettlementrateentryTwo"
                  max-height="200px">
          <el-table-column type="selection" width="50" align="center" />
          <el-table-column label="序号" align="center" prop="index" width="50"/>
<!--          <el-table-column label="组织编码" prop="orgnumber" width="150">-->
<!--            <template slot-scope="scope">-->
<!--              <el-input v-model="scope.row.orgnumber" placeholder="请输入组织编码" />-->
<!--            </template>-->
<!--          </el-table-column>-->
          <el-table-column label="组织编码" prop="orgnumber" width="150">
            <template slot-scope="scope">
              <el-input
                @change="orgEntryChange(scope.row)"
                v-model="scope.row.orgnumber"
                placeholder="请输入组织编码"/>
            </template>
          </el-table-column>
          <el-table-column label="组织名称" prop="orgname" width="350">
            <template slot-scope="scope">
              <el-input v-model="scope.row.orgname" placeholder="请输入组织名称" readonly />
            </template>
          </el-table-column>
        </el-table>


        <el-divider content-position="center">价格策略分录信息</el-divider>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAddOmsSettlementrateentry">添加</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="danger" icon="el-icon-delete" size="mini" @click="handleDeleteOmsSettlementrateentry">删除</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="danger" icon="el-icon-plus" size="mini" @click="importTemplate">下载导入模板</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="danger" icon="el-icon-plus" size="mini" @click="importExcelsettlementrateentry1">导入数据</el-button>
          </el-col>
        </el-row>
        <el-table
          height="600px"
          :data="omsSettlementrateentryList" :row-class-name="rowOmsSettlementrateentryIndex" @selection-change="handleOmsSettlementrateentrySelectionChange" ref="omsSettlementrateentry">
          <el-table-column type="selection" width="50" align="center" />
          <el-table-column label="序号" align="center" prop="index" width="50"/>
          <el-table-column label="价格类型" prop="pricetype" width="150">
            <template slot-scope="scope">
              <el-select v-model="scope.row.pricetype" placeholder="请选择价格类型">
                <el-option
                  v-for="dict in dict.type.settlement_price_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </template>
          </el-table-column>
          <el-table-column label="品类编码" prop="categorynumber" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.categorynumber" placeholder="请输入品类编码" />
            </template>
          </el-table-column>
          <el-table-column label="品类名称" prop="categoryname" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.categoryname" placeholder="请输入品类名称" />
            </template>
          </el-table-column>
          <el-table-column label="物料编码" prop="materialnumber" width="150">
            <template slot-scope="scope">
              <el-input
                @change="materiaChange(scope.row)"
                v-model="scope.row.materialnumber"
                placeholder="请输入物料编码"/>
            </template>
          </el-table-column>
          <el-table-column label="物料名称" prop="materialname" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.materialname" placeholder="请输入物料名称" />
            </template>
          </el-table-column>
          <el-table-column label="单位" prop="unitname" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.unitname" placeholder="请输入单位" />
            </template>
          </el-table-column>
          <el-table-column label="客户分组" prop="groupnumber" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.groupnumber" placeholder="请输入客户分组" />
            </template>
          </el-table-column>
          <el-table-column label="比例" prop="scale" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.scale" placeholder="请输入比例" />
            </template>
          </el-table-column>
          <el-table-column label="含税单价" prop="taxprice" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.taxprice" placeholder="请输入含税单价" />
            </template>
          </el-table-column>
          <el-table-column label="优先级" prop="priority" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.priority" placeholder="请输入优先级" />
            </template>
          </el-table-column>
<!--          <el-table-column label="父表id" prop="parentid" width="150">-->
<!--            <template slot-scope="scope">-->
<!--              <el-input v-model="scope.row.parentid" placeholder="请输入父表id" />-->
<!--            </template>-->
<!--          </el-table-column>-->
<!--          <el-table-column label="客户编码" prop="customernumber" width="150">-->
<!--            <template slot-scope="scope">-->
<!--              <el-input v-model="scope.row.customernumber" placeholder="请输入客户编码" />-->
<!--            </template>-->
<!--          </el-table-column>-->
<!--          <el-table-column label="客户名称" prop="customername" width="150">-->
<!--            <template slot-scope="scope">-->
<!--              <el-input v-model="scope.row.customername" placeholder="请输入客户名称" />-->
<!--            </template>-->
<!--          </el-table-column>-->
<!--          <el-table-column label="物料分类一级编码" prop="group1number" width="150">-->
<!--            <template slot-scope="scope">-->
<!--              <el-input v-model="scope.row.group1number" placeholder="请输入物料分类一级编码" />-->
<!--            </template>-->
<!--          </el-table-column>-->
<!--          <el-table-column label="物料分类一级名称" prop="group1name" width="150">-->
<!--            <template slot-scope="scope">-->
<!--              <el-input v-model="scope.row.group1name" placeholder="请输入物料分类一级名称" />-->
<!--            </template>-->
<!--          </el-table-column>-->
<!--          <el-table-column label="物料分类二级编码" prop="group2number" width="150">-->
<!--            <template slot-scope="scope">-->
<!--              <el-input v-model="scope.row.group2number" placeholder="请输入物料分类二级编码" />-->
<!--            </template>-->
<!--          </el-table-column>-->
<!--          <el-table-column label="物料分类二级名称" prop="group2name" width="150">-->
<!--            <template slot-scope="scope">-->
<!--              <el-input v-model="scope.row.group2name" placeholder="请输入物料分类二级名称" />-->
<!--            </template>-->
<!--          </el-table-column>-->
<!--          <el-table-column label="物料分类三级编码" prop="group3number" width="150">-->
<!--            <template slot-scope="scope">-->
<!--              <el-input v-model="scope.row.group3number" placeholder="请输入物料分类三级编码" />-->
<!--            </template>-->
<!--          </el-table-column>-->
<!--          <el-table-column label="物料分类三级名称" prop="group3name" width="150">-->
<!--            <template slot-scope="scope">-->
<!--              <el-input v-model="scope.row.group3name" placeholder="请输入物料分类三级名称" />-->
<!--            </template>-->
<!--          </el-table-column>-->
<!--          <el-table-column label="加成比率" prop="rate" width="150">-->
<!--            <template slot-scope="scope">-->
<!--              <el-input v-model="scope.row.rate" placeholder="请输入加成比率" />-->
<!--            </template>-->
<!--          </el-table-column>-->
        </el-table>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 用户导入结算策略价格分录对话框 -->
    <el-dialog :title="excels.settlementrateentry1.title" :visible.sync="excels.settlementrateentry1.show" width="400px">
      <template v-show="excels.settlementrateentry1.show">
        <div>
          <div class="container">
            {{ excels.settlementrateentry1.upload_file || "导入" }}
            <input
              type="file"
              accept=".xls,.xlsx"
              class="upload_file"
              :value="excels.settlementrateentry1.data"
              @change="readExcelsettlementrateentry1($event)"
            />
          </div>
        </div>
      </template>
    </el-dialog>

    <!-- 用户导入结算策略组织分录对话框 -->
    <el-dialog :title="excels.settlementrateentry2.title" :visible.sync="excels.settlementrateentry2.show" width="400px">
      <template v-show="excels.settlementrateentry2.show">
        <div>
          <div class="container">
            {{ excels.settlementrateentry2.upload_file || "导入" }}
            <input
              type="file"
              accept=".xls,.xlsx"
              class="upload_file"
              :value="excels.settlementrateentry2.data"
              @change="readExcelsettlementrateentry2($event)"
            />
          </div>
        </div>
      </template>
    </el-dialog>



  </div>
</template>

<script>
import { listSettlementrate, getSettlementrate, delSettlementrate, addSettlementrate, updateSettlementrate, queryOmsOrgObject, queryMaterialObject } from "@/api/settlementCenter/basedata/settlementrate";
import XLSX from "xlsx";

export default {
  name: "Settlementrate",
  dicts: ['yes_no_audit','settlement_price_type'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 子表选中数据
      checkedOmsSettlementrateentry: [],
      //分录2子表选中数据
      checkedOmsSettlementrateentryTwo:[],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 价格策略表格数据
      settlementrateList: [],
      // 价格策略分录表格数据
      omsSettlementrateentryList: [],
      //价格策略组织分录表格数据
      omsSettlementrateentrytwoList: [],
      //价格策略行数据
      settlementRateExpandRowKeys: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // excel导入相关参数
      excels:{
        settlementrateentry1:{
          show:false,
          upload_file: "",
          data : ""
        },
        settlementrateentry2:{
          show:false,
          upload_file: "",
          data : ""
        },
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        tacticsname: null,
        saleorgnumber: null,
        saleorgname: null,
        startdate: null,
        enddate: null,
        status: null,
        params:{
          orgnumber: null,
          orgname: null,
          pricetype: null,
          categorynumber: null,
          categoryname: null,
          materialnumber: null,
          materialname: null,
          groupnumber: null,
        }
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询价格策略列表 */
    getList() {
      this.loading = true;
      listSettlementrate(this.queryParams).then(response => {
        this.settlementrateList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        tacticsname: null,
        saleorgnumber: null,
        saleorgname: null,
        startdate: null,
        enddate: null,
        status: 0
      };
      this.omsSettlementrateentryList = [];
      this.omsSettlementrateentrytwoList = [];
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    //监听row-click事件，实现选中
    rowClick(row, column, event) {
      // console.log(this.ids);
      let refsElTable = this.$refs.serveTable; // 获取表格对象
      refsElTable.toggleRowSelection(row);  //如过重复选中，则取消选中
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加价格策略";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getSettlementrate(id).then(response => {
        this.form = response.data;
        this.omsSettlementrateentryList = response.data.omsSettlementrateentryList;
        this.omsSettlementrateentrytwoList = response.data.omsSettlementrateentrytwoList;
        this.open = true;
        this.title = "修改价格策略";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.form.omsSettlementrateentryList = this.omsSettlementrateentryList;
          this.form.omsSettlementrateentrytwoList = this.omsSettlementrateentrytwoList;
          console.log(this.form.omsSettlementrateentrytwoList);
          if (this.form.id != null) {
            console.log(this.form.omsSettlementrateentrytwoList);
            updateSettlementrate(this.form).then(response => {
              switch (response.data) {
                case -1:
                  this.$modal.msgError("修改失败:价格类型为手工维护时，物料编码必填，其余情况物料编码不能填，且品类编码不能为空");
                  break;
                case -2:
                  this.$modal.msgError("修改失败:状态为已审核的数据，分录不能为空");
                  break;
                case -3:
                  this.$modal.msgError("修改失败:单据头组织编码和名字不能为空");
                  break;
                case -4:
                  this.$modal.msgError("修改失败:单据头组织不存在");
                  break;
                default:
                  if(response.data>0){
                    this.$modal.msgSuccess("修改成功");
                    this.open = false;
                    this.getList();
                  }else{
                    this.$modal.msgError("修改失败:请核验数据");
                  }
              }
            });
          } else {
            console.log(this.form.omsSettlementrateentrytwoList);
            addSettlementrate(this.form).then(response => {
              switch (response.data) {
                case -1:
                  this.$modal.msgError("新增失败:价格类型为手工维护时，物料编码必填，其余情况物料编码不能填，且品类编码不能为空");
                  break;
                case -2:
                  this.$modal.msgError("新增失败:状态为已审核的数据，分录不能为空");
                  break;
                case -3:
                  this.$modal.msgError("新增失败:单据头组织编码和名字不能为空");
                  break;
                case -4:
                  this.$modal.msgError("新增失败:单据头组织不存在");
                  break;
                default:
                  if(response.data>0){
                    this.$modal.msgSuccess("新增成功");
                    this.open = false;
                    this.getList();
                  }else{
                    this.$modal.msgError("新增失败:请核验数据");
                  }
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除价格策略编号为"' + ids + '"的数据项？').then(function() {
        return delSettlementrate(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
	/** 价格策略分录序号 */
    rowOmsSettlementrateentryIndex({ row, rowIndex }) {
      row.index = rowIndex + 1;
    },
    /** 价格策略分录添加按钮操作 */
    handleAddOmsSettlementrateentry() {
      let obj = {};
      obj.categorynumber = "";
      obj.categoryname = "";
      obj.materialnumber = "";
      obj.materialname = "";
      obj.unitname = "";
      obj.pricetype = "1";
      obj.groupnumber = "";
      obj.scale = "";
      obj.taxprice = "";
      obj.priority = "";
      obj.parentid = "";
      obj.customernumber = "";
      obj.customername = "";
      obj.group1number = "";
      obj.group1name = "";
      obj.group2number = "";
      obj.group2name = "";
      obj.group3number = "";
      obj.group3name = "";
      obj.rate = "";
      this.omsSettlementrateentryList.push(obj);
    },
    /** 价格策略分录删除按钮操作 */
    handleDeleteOmsSettlementrateentry() {
      if (this.checkedOmsSettlementrateentry.length == 0) {
        this.$modal.msgError("请先选择要删除的价格策略分录数据");
      } else {
        const omsSettlementrateentryList = this.omsSettlementrateentryList;
        const checkedOmsSettlementrateentry = this.checkedOmsSettlementrateentry;
        this.omsSettlementrateentryList = omsSettlementrateentryList.filter(function(item) {
          return checkedOmsSettlementrateentry.indexOf(item.index) == -1
        });
      }
    },
    /** 复选框选中数据 */
    handleOmsSettlementrateentrySelectionChange(selection) {
      this.checkedOmsSettlementrateentry = selection.map(item => item.index)
    },



    rowOmssettlementrateentryTwoIndex({ row, rowIndex }) {
      row.index = rowIndex + 1;
    },
    /** 价格策略组织分录添加按钮操作 */
    handleAddOmssettlementrateentryTwo() {
      let obj = {};
      obj.orgnumber = "";
      obj.orgname = "";
      this.omsSettlementrateentrytwoList.push(obj);
    },
    /** 价格策略组织分录删除按钮操作 */
    handleDeleteOmssettlementrateentryTwo() {
      if (this.checkedOmsSettlementrateentryTwo.length == 0) {
        this.$modal.msgError("请先选择要删除的价格策略组织分录数据");
      } else {
        const omsSettlementrateentrytwoList = this.omsSettlementrateentrytwoList;
        const checkedOmsSettlementrateentryTwo = this.checkedOmsSettlementrateentryTwo;
        this.omsSettlementrateentrytwoList = omsSettlementrateentrytwoList.filter(function(item) {
          return checkedOmsSettlementrateentryTwo.indexOf(item.index) == -1
        });
      }
    },
    /** 复选框选中数据 */
    handleOmssettlementrateentryTwoSelectionChange(selection) {
      this.checkedOmsSettlementrateentryTwo = selection.map(item => item.index)
    },



    /** 导出按钮操作 */
    handleExport() {
      this.download('settlementCenter/basedata/settlementrate/export', {
        ...this.queryParams
      }, `settlementrate_${new Date().getTime()}.xlsx`)
    },
    materiaChange(val) {
      //查询物料
      if (val.materialnumber === "") {
        val.materialname = "";
      } else {
        queryMaterialObject(val.materialnumber).then(response => {
          // 物料名称
          if(response.data == null
            ||response.data.materialname == null||response.data.materialname === ""){
            val.materialname = "";
          }else{
            val.materialname = response.data.materialname;
          }
          // 计量单位名称
          if(response.data == null
            ||response.data.baseunitname == null||response.data.baseunitname === ""){
            val.unitname = "";
          }else{
            val.unitname = response.data.baseunitname;
          }
        });
      }
    },
    orgChange() {
      //查询单头结算组织
      if (this.form.saleorgnumber === "") {
        this.form.saleorgname = "";
      } else {
        queryOmsOrgObject(this.form.saleorgnumber).then(response => {
          // 数据源
          if(response.data == null
            ||response.data.orgname == null||response.data.orgname === ""){
            this.form.saleorgname = "";
          }else{
            this.form.saleorgname = response.data.orgname;
          }
        });
      }
    },
    orgEntryChange(val) {
      //查询分录结算组织
      if (val.orgnumber === "") {
        val.orgname = "";
      } else {
        queryOmsOrgObject(val.orgnumber).then(response => {
          // 数据源
          if(response.data == null
            ||response.data.orgname == null||response.data.orgname === ""){
            val.orgname = "";
          }else{
            val.orgname = response.data.orgname;
          }
        });
      }
    },
    /** 单据头序号 */
    rowBillHeadIndex({ row, rowIndex }) {
      row.index = rowIndex + 1;
      let rowName = "",
        findRow = this.ids.indexOf(row.id);
      if (findRow !== -1) {
        rowName = "current-row ";
      }
      row.index = rowIndex + 1;
      return rowName; //也可以再加上其他类名 如果有需求的话
    },


    //下载分录模板
    importTemplate() {
      this.download('settlementCenter/basedata/settlementrate/importTemplate', {
      }, `settlementPriceEntry_template_${new Date().getTime()}.xlsx`)
    },
    //下载分录模板
    importTemplateEntry2() {
      this.download('settlementCenter/basedata/settlementrate/importTemplateEntry2', {
      }, `settlementOrgUnitEntry_template_${new Date().getTime()}.xlsx`)
    },
    // 点击进行导入
    importExcelsettlementrateentry1() {
      this.excels.settlementrateentry1.upload_file = "";
      this.excels.settlementrateentry1.data = "";
      this.excels.settlementrateentry1.show = true;
    },
    // 点击进行导入
    importExcelsettlementrateentry2() {
      this.excels.settlementrateentry2.upload_file = "";
      this.excels.settlementrateentry2.data = "";
      this.excels.settlementrateentry2.show = true;
    },
    //解析导入的excel文件
    readExcelsettlementrateentry1(e) {
      // 读取表格文件
      let that = this;
      const files = e.target.files;
      if (files.length <= 0) {
        return false;
      } else if (!/\.(xls|xlsx)$/.test(files[0].name.toLowerCase())) {
        this.$message({
          message: "上传格式不正确，请上传xls或者xlsx格式",
          type: "warning"
        });
        return false;
      } else {
        // 更新获取文件名
        that.excels.settlementrateentry1.upload_file = files[0].name;
        // console.log("that.excel.upload_file = files[0].name;")
      }

      const fileReader = new FileReader();
      // console.log("new FileReader();")
      fileReader.onload = ev => {
        try {
          const data = ev.target.result;
          // console.log("const data = ev.target.result;")
          const workbook = XLSX.read(data, {
            type: "binary"
          });
          // console.log("XLSX.read")
          const wsname = workbook.SheetNames[0]; //取第一张表
          // console.log("//取第一张表")
          const ws = XLSX.utils.sheet_to_json(workbook.Sheets[wsname]); //生成json表格内容
          // console.log("//生成json表格内容")

          // 从解析出来的数据中提取相应的数据
          ws.forEach(item => {
            this.omsSettlementrateentryList.push({
              pricetype : item["价格类型"],
              categorynumber : item["品类编码"],
              categoryname : item["品类名称"],
              materialnumber : item["物料编码"],
              materialname : item["物料名称"],
              unitname : item["单位"],
              groupnumber : item["客户分组"],
              scale : item["比例"],
              taxprice : item["含税单价"],
              priority : item["优先级"]
            });
            console.log("//开始解析插入数据")
          });
          // this.excel.data = "";
          // 结束解析动画
          // excel.upload_file = "";
          this.excels.settlementrateentry1.show = false;
        } catch (e) {
          return false;
        }
      };
      fileReader.readAsBinaryString(files[0]);
    },
    //解析导入的excel文件
    readExcelsettlementrateentry2(e) {
      // 读取表格文件
      // console.log("读取表格文件")
      let that = this;
      const files = e.target.files;
      if (files.length <= 0) {
        return false;
      } else if (!/\.(xls|xlsx)$/.test(files[0].name.toLowerCase())) {
        this.$message({
          message: "上传格式不正确，请上传xls或者xlsx格式",
          type: "warning"
        });
        return false;
      } else {
        // 更新获取文件名
        that.excels.settlementrateentry2.upload_file = files[0].name;
        // console.log("that.excel.upload_file = files[0].name;")
      }

      const fileReader = new FileReader();
      // console.log("new FileReader();")
      fileReader.onload = ev => {
        try {
          const data = ev.target.result;
          // console.log("const data = ev.target.result;")
          const workbook = XLSX.read(data, {
            type: "binary"
          });
          // console.log("XLSX.read")
          const wsname = workbook.SheetNames[0]; //取第一张表
          // console.log("//取第一张表")
          const ws = XLSX.utils.sheet_to_json(workbook.Sheets[wsname]); //生成json表格内容
          // console.log("//生成json表格内容")

          // 从解析出来的数据中提取相应的数据
          ws.forEach(item => {
            this.omsSettlementrateentrytwoList.push({
              orgnumber : item["组织编码"],
              orgname : item["组织名称"]
            });
            console.log("//开始解析插入数据")
          });
          // this.excel.data = "";
          // 结束解析动画
          // excel.upload_file = "";
          this.excels.settlementrateentry2.show = false;
        } catch (e) {
          return false;
        }
      };
      fileReader.readAsBinaryString(files[0]);
    },
    closeOrOpenAll(){
      if (this.settlementRateExpandRowKeys.length > 0){
        this.settlementRateExpandRowKeys = [];
        return;
      }
      if (this.settlementRateExpandRowKeys.length == 0){
        this.settlementRateExpandRowKeys = this.settlementrateList.map((item) => {
          return item.id
        })
      }
    }



  }
};
</script>



<style lang="scss" scoped>
.el-table {
  border-top: none !important;
}

.el-table__expanded-cell {
  padding: 0 !important;
}

.tableWrap {
  width: 100%;
}

.el-tabs__nav-scroll {
  padding: 0 20px;
  box-sizing: border-box;
}

.tableWrap .el-table {
  width: 1240px;
  margin: 0 auto;
}

.el-icon.el-icon-arrow-right {
  color: #fff;
}

.el-table__row.expanded {
  background: #fff !important;
  position: relative !important;
  top: -100px !important;
  border: 1px solid red;
}

.el-tabs__content {
  display: none;
}

.el-table__row.expanded > td {
  padding: 7px 0;
}

.el-table__row.expanded {
  border: 1px solid #E5E5E5;
}

.el-table__row.expanded:first-child {
  border-bottom: none;
}
.childTable1{
  margin-left: 200px;
  width: 1150px;
}.childTable{
   margin-left: 200px;
   width: 1150px;
 }
.childTable .el-table__body {
  border-top: 1px solid #E5E5E5;
}

.childTable .el-table__row.expanded > td:first-child {
  border-left: 1px solid #E5E5E5;
}

.childTable .el-table__row.expanded > td:last-child {
  border-right: 1px solid #E5E5E5;
}

.el-tabs__header.is-top {
  border-bottom: none;
}

//.childTable .el-table__header-wrapper {
//  display: none;
//}

.conWrap {
  height: 44px;
  background: #E5E5E5;
  line-height: 44px;
  padding-left: 10px;
  font-size: 14px;
  font-family: Microsoft YaHei;
  line-height: 19px;
  color: #333333;
}

.conWrap > span {
  line-height: 44px;
}

.el-table .has-gutter .is-leaf {
  position: relative !important;
  left: -48px !important;
}

.el-table .has-gutter .is-leaf:last-child {
  position: relative !important;
  left: 0px !important;
}

.el-table__header-wrapper {
  background: #EBEBEB;
}

.el-table .has-gutter > tr > th {
  background: #EBEBEB;
  font-size: 14px;
  font-family: Microsoft YaHei;
  font-weight: bold;
  line-height: 19px;
  color: #333333;
}
</style>
